#include "CombatComponent.h"
#include "OrientationComponent.h"
#include "DirectionalAbility.h"
#include "NonTargettedAbility.h"
#include "TargettedAbility.h"
#include "Entity.h"
#include "StatusComponent.h"

const HashedString CombatComponent::type("CombatComponent");

CombatComponent::CombatComponent( Entity* parent ) : IComponent(parent)
{
	m_combatant = new Combat::Combatant( parent );

	StatusComponent* status = (StatusComponent*)(m_parent->FindComponent(StatusComponent::type));
	if (status)
	{
		StatusComponent::Status& health = status->getStatus("HealthPoints");
		StatusComponent::Status& physicalDamage = status->getStatus("PhysicalDamage");
		StatusComponent::Status& specialDamage = status->getStatus("SpecialDamage");
	
		m_health = new DoubleValueTrigger<int>(&health, &(m_combatant->Health()));
		m_physicalDamage = new DoubleValueTrigger<int>(&physicalDamage, &(m_combatant->PhysicalDamage()));
		m_specialDamage = new DoubleValueTrigger<int>(&specialDamage, &(m_combatant->SpecialDamage()));
	}
}

Pointer<Combat::Combatant> CombatComponent::Combatant()
{
	return m_combatant;
}

const HashedString& CombatComponent::Type()
{
	return type;
}

static inline float getTargetDistance( CombatComponent* me, CombatComponent* target )
{
	Entity* parent = me->Parent();
	Entity* targetParent = target->Parent();
	OrientationComponent* orientation = (OrientationComponent*)(parent->FindComponent(OrientationComponent::type));
	OrientationComponent* targetOrientation = (OrientationComponent*)(targetParent->FindComponent(OrientationComponent::type));
	Maths::Vector3D position, targetPosition;
	position = orientation->getPosition().getObject();
	targetPosition = targetOrientation->getPosition().getObject();

	return targetPosition.Distance(position);
}

std::string CombatComponent::ToString() const
{
	return std::string();
}

bool CombatComponent::ToXML( tinyxml2::XMLPrinter& printer )
{
	return true;
}
